{% extends "public/base.html" %}
{% block main %}
<div class="admin-content">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf">
            <a href="{{url(nav[0]['url'])}}"><strong class="am-text-primary am-text-lg">{{nav[0]['title']}}</strong></a>
            {% if nav[1]['title'] is not empty %} /<a href="{{url(nav[1]['url'])}}" style="color:#333"><small>{{nav[1]['title']}}</small></a>{% endif %}
        </div>
    </div>
    <div class="am-g">
        <form action="{{url('permission/create')}}" class="am-form am-form-horizontal" method="post">
            <div class="am-u-sm-12">
                <div class="am-form-group">

                </div>
                <div class="am-form-group">
                    <label for="allCheckBox" class="am-form-label am-text-danger">全选</label>
                    <input id="allCheckBox" type="checkbox">

                    <select id="role_id" class="am-form-field" name="role_id" data-am-selected="{btnSize: ''}">
                        {% if roles is empty %}
                        <option value="0">暂无管理角色</option>
                        {% else %}

                        {%for role in roles %}
                        <option value="{{role.id}}" {% if role.id== current_id %}selected {% endif %}>{{role.title}}
                        </option>
                        {%endfor%}
                        {% endif %}
                    </select>

                </div>
            </div>
            {% if nodes is empty %}

            {% else %}
            {% for data in nodes %}
            <div class="am-u-sm-12">
                <table class="am-table am-table-bordered am-table-radius">
                    <thead>
                    <tr>
                        <td class="am-u-sm-1">
                            <input class="parentCheckBox" type="checkbox" name="node[]" value="{{data['url']}}" <?php if(in_array($data['url'],$url)){echo 'checked="checked"';}?>>
                        </td>
                        <td class="am-u-sm-11">{{data['title']}}</td>
                    </tr>
                    </thead>
                    <tbody>
                    {% if data['is_group'] == 1 %}
                    {% for dataChild in data['_child'] %}
                    <tr>
                        <td class="am-u-sm-2 am-text-right">
                            <input class="childCheckBox" type="checkbox" name="node[]" value="{{dataChild['url']}}" <?php if(in_array($dataChild['url'],$url)){echo 'checked="checked"';}?>>
                        </td>
                        <td class="am-u-sm-10">└{{dataChild['title']}}</td>
                    </tr>
                    {% endfor %}
                    {% endif %}
                    </tbody>
                </table>
            </div>
            {% endfor %}
            {% endif %}

            <div class="am-form-group">
                <div class="am-u-sm-9 am-u-sm-push-1">
                    <input class="am-btn am-btn-primary" type="submit" value="保存修改">
                </div>
            </div>
        </form>
    </div>
</div>
{% endblock %}

{% block javascript %}
<script language="JavaScript">
    $(document).ready(function () {
        $('#allCheckBox').on('change', function () {
            $(this).closest('.am-g').find('input').prop('checked', this.checked);
        });

        $('.parentCheckBox').on('change', function () {
            $(this).closest('.am-table').find('.childCheckBox').prop('checked', this.checked);
        });
    });
</script>
{% endblock %}
